package starlingui.component
{
	import com.imcrl.component.ILayoutable;
	import com.imcrl.component.itemRender.IListItemRender;
	import com.imcrl.component.pictab.PictabItem;
	import com.imcrl.core.ClassFactory;
	import com.imcrl.event.AdvListItemEvent;
	import com.imcrl.event.ListItemEvent;
	import com.imcrl.manager.RenderManager;
	
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.Graphics;
	import flash.display.Shape;
	import flash.filters.DropShadowFilter;
	import flash.geom.Matrix;
	import flash.geom.Point;
	
	import starling.display.Image;
	import starling.display.Sprite;
	import starling.textures.Texture;
	
	import starlingui.vo.IconVO;
	
	public class FolderList extends DeskList
	{
		public static var shader:BitmapData;
		
		
		private var background:Image;
		
		private var size:int=20;
		private var top:int;
		private var shape:Shape;
		public function FolderList()
		{
			super();	
			
			top=Math.sqrt(Math.pow(size*1.5,2)-Math.pow(size,2));
			
			shape=new  Shape();
			var f:DropShadowFilter=new DropShadowFilter();
			f.angle=90;
			f.blurX=f.blurY=15;
			f.color=0x333333;
			f.distance=1;
			f.inner=true;
			shape.filters=[f];
			
			innerList.y=top;
		}
		
		private function itemDragRecognizedHandle(event:AdvListItemEvent):void{
			if(hasEventListener(event.type)){
				this.dispatchEvent(event);
			}
		}
		
		
		
		
		
		public function show(w:int,h:int,x:int):void{
			
			if(shape.width !=w || shape.height !=h){
				//todo;
			}
			
			var g:Graphics=shape.graphics;
			g.clear();
			g.beginBitmapFill(shader,null,true,false);
			g.drawRect(0,0,w,h);
			
			var left:int=x-size;
			var right:int=x+size;
			
			g.moveTo(left,0);
			g.lineTo(x,-top);
			g.lineTo(right,0);
			g.lineTo(left,0);
			g.endFill();
			
			var matrix:Matrix=new Matrix();
			matrix.translate(0,top);
			var bmd:BitmapData=new BitmapData(shape.width,shape.height,true,0);
			bmd.draw(shape,matrix);
			
			
			var texture:Texture=Texture.fromBitmapData(bmd,false);
			if(background==null){
				background=new Image(texture);
				background.touchable=false;
				this.addChildAt(background,0);
			}else{
				background.texture=texture;
				background.readjustSize();
			}
		}
		
		
		public function displayList(value:Vector.<IconVO>):int{
			_data=value;
			innerList.displayList(value);
			//;
			RenderManager.instance.remove(innerList);
			innerList.rende();
			
			return Math.ceil(value.length/_layout.col)*_layout.itemH;
		}
		
		override public function set data(value:*):void{
			throw new Error("不允许使用此方法");	
		}
		
		override public function get data():*{
			return _data;
		}
		
		
		
		override public function set y(value:Number):void{
			value-=top;
			super.y=value;
		}
	}
}